﻿// ************************************************* //
// BGA_LGAAdapter.cs
// Author: Chris Wu
// Email: cwu@dataio.com
// ------------------------------------ //
// version 1.0 - Initial Create
// date: March 24th, 2010
//
// version 1.1 - Modify to BGA_LGAAdapter
// date: April 25th, 2010
// ------------------------------------ //
//
// ************************************************* //

using System;

namespace Common
{
    /// <summary>
    /// Description of BGA_LGAAdapter.
    /// </summary>
    public class BGA_LGAAdapter
	{
        // ********************************************** //
        // pin assignment array (8 x 15) //

        // A1 x x x x x x x x x x x x x A15 //
        // B1 x x x x x x x x x x x x x B15 //
        // C1 x x x x x x x x x x x x x C15 //
        // D1 x x x x x x x x x x x x x D15 //
        // E1 x x x x x x x x x x x x x E15 //
        // F1 x x x x x x x x x x x x x F15 //
        // G1 x x x x x x x x x x x x x G15 //
        // H1 x x x x x x x x x x x x x H15 //

        // ********************************************** //
        
        private static string[] BGA_LGA_alph = {   "A", "B", "C", "D", "E", "F", "G",  // 1 - 7
                                                "H", "J", "K", "L", "M", "N", "P",  // 8 - 14
                                                "R", "T", "U", "V", "W", "Y", "AA", // 15 - 21
                                                "AB", "AC", "AD", "AE", "AF"};      // 22 - 26
        private int m_PinMapId;            // PinMapId
        private int m_RowNum;               // RowNum
        private int m_ColumnNum;            // ColumnNum
        private int m_TotalPins;            // TotalPins
        private string[] m_PositionList;    // PositionList
        private string[] m_LabelList;       // LabelList

        // BGA_LGAAdapter Constructor
        public BGA_LGAAdapter()
        {
            m_RowNum = 0;
            m_ColumnNum = 0;
            m_TotalPins = 0;
            m_PositionList = null;
            m_LabelList = null;
        }

        // get and set m_PinMapId
        public int PinMapId
        {
            get { return m_PinMapId; }
            set { m_PinMapId = value; }
        }

        // get and set m_TotalPins
        public int TotalPins
        {
            get { return m_TotalPins; }
            set { m_TotalPins = value; }
        }

        // get and set m_RowNum
        public int RowNum
        {
            get { return m_RowNum; }
            set { m_RowNum = value; FillPositionList(); }
        }

        // get and set m_ColumnNum
        public int ColumnNum
        {
            get { return m_ColumnNum; }
            set { m_ColumnNum = value; FillPositionList(); }
        }

        // get and set m_PositionList
        public string[] PositionList
        {
            get { return m_PositionList; }
            set { m_PositionList = value; }
        }

        // get and set m_LabelList
        public string[] LabelList
        {
            get { return m_LabelList; }
            set { m_LabelList = value; }
        }

        // function FillPositionList
        // according to the parameters m_RowNum and m_Column to fill the PositionList
        // in the meantime to set initial string for LabelList
        private void FillPositionList()
        {
            m_PositionList = new string[m_RowNum * m_ColumnNum];
            m_LabelList = new string[m_RowNum * m_ColumnNum];            
            for (int i = 0; i < m_RowNum; i ++)
            {
                for (int j = 0; j < m_ColumnNum; j ++)
                {
                    m_PositionList[i * m_ColumnNum + j] = BGA_LGA_alph[i] + (j + 1).ToString();
                    m_LabelList[i * m_ColumnNum + j] = "";
                }
            }

            return;
        }

        // get m_PositionList[index]
        public string GetPosition(int index)
        {
            string str = "";
            if (index > m_ColumnNum * m_RowNum - 1 || index < 0)
            { 
                // there is no index record
                return str;
            }

            str = m_PositionList[index];

            return str;
        }

        // set m_LabelList[index] with label
        public void SetLabelList(int index, string label)
        {
            if (index > m_ColumnNum * m_RowNum - 1 || index < 0)
            {
                // there is no index record
                return;
            }

            m_LabelList[index] = label;

            return;
        }

        // get m_LabelList[index]
        public string GetLabel(int index)
        {
            string str = "";
            if (index > m_ColumnNum * m_RowNum - 1 || index < 0)
            {
                // there is no index record
                return str;
            }

            str = m_LabelList[index];

            return str;
        }
	}
}
